package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.component.image._enum.ImageEnum;
import com.frogs.framework.component.image._enum.ImgStatusEnum;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;
import com.opensymphony.oscache.util.StringUtil;

public class UploadImgRequest extends Request {
	
	private static final long serialVersionUID = 520939211521317493L;
	
	private HttpRequestInfo requestInfo;
	private String refResource;
	private int resourceId;
	private int userId;
	private String userName;
	private int forceRenew;
	private int type;
	private String direct;
	private String fileName;
	private int resize;
	private String ip;
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		refResource = requestInfo.getParameter(ApiUrlParamEnum.refResource.getParamName()); 
		resourceId = requestInfo.getIntParameter(ApiUrlParamEnum.resourceId.getParamName(),0);
		userName = requestInfo.getParameter(ApiUrlParamEnum.accountName.getParamName());
		userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		forceRenew = requestInfo.getIntParameter(ApiUrlParamEnum.force.getParamName(), ImgStatusEnum.NOT_FORCE_RENEW.getId());
		type = requestInfo.getIntParameter(ApiUrlParamEnum.type.getParamName(), ImageEnum.IMG_DEFAULT.getId());
		fileName = requestInfo.getParameter(ApiUrlParamEnum.fileName.getParamName());
		direct = requestInfo.getParameter(ApiUrlParamEnum.dirName.getParamName());
		resize = requestInfo.getIntParameter(ApiUrlParamEnum.resize.getParamName(), ImgStatusEnum.UN_NEED_RESIZE.getId());
		ip = requestInfo.getUserIp();
		
		if(StringUtil.isEmpty(refResource) && resourceId == 0) {
			throw new RequestIllegalException("缺少必要参数，请确认");
		}
		
		this.setRequestInfo(requestInfo);
	}
	
	public HttpRequestInfo getRequestInfo() {
		return requestInfo;
	}

	public void setRequestInfo(HttpRequestInfo requestInfo) {
		this.requestInfo = requestInfo;
	}
	
	public String getRefResource() {
		return refResource;
	}

	public void setRefResource(String refResource) {
		this.refResource = refResource;
	}

	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}
	
	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public int getForceRenew() {
		return forceRenew;
	}

	public void setForceRenew(int forceRenew) {
		this.forceRenew = forceRenew;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	public String getDirect() {
		return direct;
	}

	public void setDirect(String direct) {
		this.direct = direct;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public int getResize() {
		return resize;
	}

	public void setResize(int resize) {
		this.resize = resize;
	}
	
	public String getIp() {
		return this.ip;
	}
	
	public void setIp(String ip) {
		this.ip = ip;
	}

}
